{"ast":null,"code":"import axios from 'axios';\nimport { baseUrl, exceptionUrl, refreshToken } from '../routes';\nimport { store } from '../index';\nconst apiClient = axios.create({\n  withCredentials: false,\n  // к каждому запросу cookie цепляются автоматически\n  baseURL: baseUrl()\n});\napiClient.interceptors.request.use(config => {\n  var _config$url;\n  if ((_config$url = config.url) !== null && _config$url !== void 0 && _config$url.includes(exceptionUrl())) {\n    return config;\n  }\n  // @ts-ignore\n  config.headers.Authorization = `Bearer ${localStorage.getItem(`${process.env.REACT_APP_NAME_TOKEN}`)}`;\n  return config;\n});\napiClient.interceptors.response.use(config => {\n  return config;\n}, async error => {\n  const originalRequest = error.config;\n  if (error.response.status === 401 && error.config && !originalRequest._isRetry) {\n    console.log(localStorage.getItem(`${process.env.REACT_APP_NAME_REFRESH_TOKEN}`));\n    originalRequest._isRetry = true;\n    try {\n      const response = await axios.post(refreshToken(), {\n        \"refresh_token\": localStorage.getItem(`${process.env.REACT_APP_NAME_REFRESH_TOKEN}`)\n      });\n      store.setTokensTolLocalStorage(response);\n      return apiClient.request(originalRequest);\n    } catch (e) {\n      store.logout();\n    }\n  }\n  throw error;\n});\nexport default apiClient;","map":{"version":3,"names":["axios","baseUrl","exceptionUrl","refreshToken","store","apiClient","create","withCredentials","baseURL","interceptors","request","use","config","url","includes","headers","Authorization","localStorage","getItem","process","env","REACT_APP_NAME_TOKEN","response","error","originalRequest","status","_isRetry","console","log","REACT_APP_NAME_REFRESH_TOKEN","post","setTokensTolLocalStorage","e","logout"],"sources":["/data/messenger.client/src/http/index.ts"],"sourcesContent":["import axios from 'axios';\nimport {baseUrl, exceptionUrl, refreshToken} from '../routes';\nimport {AuthResponse} from \"../models/response/AuthResponse\";\nimport {store} from '../index'\n\nconst apiClient = axios.create({\n    withCredentials: false, // к каждому запросу cookie цепляются автоматически\n    baseURL: baseUrl()\n});\n\napiClient.interceptors.request.use((config) => {\n    if (config.url?.includes(exceptionUrl())) {\n        return config;\n    }\n    // @ts-ignore\n    config.headers.Authorization = `Bearer ${localStorage.getItem(`${process.env.REACT_APP_NAME_TOKEN}`)}`;\n    return config;\n});\n\napiClient.interceptors.response.use((config) => {\n    return config;\n}, async (error) => {\n    const originalRequest = error.config;\n\n    if (\n        error.response.status === 401 &&\n        error.config &&\n        !originalRequest._isRetry\n    ) {\n        console.log(localStorage.getItem(`${process.env.REACT_APP_NAME_REFRESH_TOKEN}`))\n        originalRequest._isRetry = true;\n        try {\n            const response = await axios.post<AuthResponse>(refreshToken(),\n                {\"refresh_token\": localStorage.getItem(`${process.env.REACT_APP_NAME_REFRESH_TOKEN}`)}\n            );\n            store.setTokensTolLocalStorage(response);\n\n            return apiClient.request(originalRequest);\n        } catch (e) {\n            store.logout();\n        }\n    }\n    throw error;\n});\n\nexport default apiClient;"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAAQC,OAAO,EAAEC,YAAY,EAAEC,YAAY,QAAO,WAAW;AAE7D,SAAQC,KAAK,QAAO,UAAU;AAE9B,MAAMC,SAAS,GAAGL,KAAK,CAACM,MAAM,CAAC;EAC3BC,eAAe,EAAE,KAAK;EAAE;EACxBC,OAAO,EAAEP,OAAO;AACpB,CAAC,CAAC;AAEFI,SAAS,CAACI,YAAY,CAACC,OAAO,CAACC,GAAG,CAAEC,MAAM,IAAK;EAAA;EAC3C,mBAAIA,MAAM,CAACC,GAAG,wCAAV,YAAYC,QAAQ,CAACZ,YAAY,EAAE,CAAC,EAAE;IACtC,OAAOU,MAAM;EACjB;EACA;EACAA,MAAM,CAACG,OAAO,CAACC,aAAa,GAAI,UAASC,YAAY,CAACC,OAAO,CAAE,GAAEC,OAAO,CAACC,GAAG,CAACC,oBAAqB,EAAC,CAAE,EAAC;EACtG,OAAOT,MAAM;AACjB,CAAC,CAAC;AAEFP,SAAS,CAACI,YAAY,CAACa,QAAQ,CAACX,GAAG,CAAEC,MAAM,IAAK;EAC5C,OAAOA,MAAM;AACjB,CAAC,EAAE,MAAOW,KAAK,IAAK;EAChB,MAAMC,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